/**
 * @param {number[]} temperatures
 * @return {number[]}
 */
var dailyTemperatures = function (temperatures) {
  const stack = []
  const ans = new Array(temperatures.length).fill(0)
  for (let i = 0; i < temperatures.length; i++) {
      while (stack.length > 0 && temperatures[stack[stack.length - 1]] < temperatures[i]) {
        let inx = stack.pop()
        ans[inx] = i - inx
      }
      stack.push(i)
  }
  return ans
};
console.log(dailyTemperatures([73,74,75,71,69,72,76,73]));